#  -*- coding:utf-8 -*- 
"""
@ author: 罗金盛
@ time: 2023/11/16 
@ file: 爬取豆瓣.py

"""
import requests
from lxml import etree
import re

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
}

response = requests.get('https://movie.douban.com/cinema/nowplaying/guangzhou/', headers=headers)

data = response.text
html=etree.HTML(data)

movies = html.xpath('/html/body/div[3]/div[1]/div/div[1]/div[3]/div[2]/ul/li[*]/ul/li[2]/a/@href')
for movie in movies:
    url = movie

    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
    }
    response = requests.get(url=url, headers=headers)
    data1 = response.text
    html1 = etree.HTML(data1)
    name = html1.xpath('/html/body/div[*]/div[*]/h1/span[1]/text()')
    item = {
        '电影链接': url,
        '电影名字': name,

    }
    print(item)





